package topofstack.networkserverutils;

import topofstack.networkserverutils.fragments.DeliveryTime;
import topofstack.networkserverutils.fragments.EmailServerInfo;
import topofstack.networkserverutils.fragments.EmailServerTest;
import topofstack.networkserverutils.fragments.ServerTestingFunctions;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        ActionBar actionBar = getActionBar();
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		
		ActionBar.Tab functionsTab = actionBar.newTab().setText("Functions");
		ActionBar.Tab emailServerTestTab = actionBar.newTab().setText("Email Server");
		ActionBar.Tab deliveryTimeTab = actionBar.newTab().setText("Delivery Time");
		ActionBar.Tab serverInfoTab = actionBar.newTab().setText("Server Info");
		
		Fragment functionsFragment = new ServerTestingFunctions();
		Fragment emailServerTestFragment = new EmailServerTest();
		Fragment deliveryTimeFragment = new DeliveryTime();
		Fragment serverInfoFragment = new EmailServerInfo();
		
		functionsTab.setTabListener(new MyTabListner(functionsFragment));
		emailServerTestTab.setTabListener(new MyTabListner(emailServerTestFragment));
		deliveryTimeTab.setTabListener(new MyTabListner(deliveryTimeFragment));
		serverInfoTab.setTabListener(new MyTabListner(serverInfoFragment));
		
		actionBar.addTab(functionsTab);
		actionBar.addTab(emailServerTestTab);
		actionBar.addTab(deliveryTimeTab);
		actionBar.addTab(serverInfoTab);
    }
    
    class MyTabListner implements ActionBar.TabListener {
    	
    	public Fragment fragment;
    	
    	public MyTabListner(Fragment fragment) {
    		this.fragment = fragment;
    	}

		public void onTabSelected(Tab tab, FragmentTransaction ft) {
			ft.replace(R.id.fragment_container, fragment);
		}

		public void onTabUnselected(Tab tab, FragmentTransaction ft) {
			ft.remove(fragment);
		}

		public void onTabReselected(Tab tab, FragmentTransaction ft) {
			
		}
    }
}